<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>
    <link rel="stylesheet" href="../css/common.css">
    <link rel="stylesheet" href="../css/start.css">
    <link rel="stylesheet" href="../css/login.css">
</head>
<body>
    <div class="nav">
        <img src="../img/logo.png" alt="">
        <span class="title">TQ02博客系统</span>
        <span class="spacer"></span>
    </div>

    <div class="login-container">
        <div class="login-dialog">
            <h1>博TQ系统注册</h1>
            <div class="kk">
                用户名：<input type="text" id="username" name="username">
            </div>

            <div class="kk">
                密码：&nbsp;&nbsp;&nbsp;<input type="password" id="password" name="password">
            </div>

            <div class="kk">
                确认密码：&nbsp;&nbsp;&nbsp;<input type="password" id="passwords" name="passwords">
            </div>
            <div id="new" class="kk">
    
            </div>
            <div class="row" id="Div1">
            <input type="submit" name="注册" id="submit" >
            </div>

        </div>
    </div>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
        <script>

                $("#submit").click(function () {
                    let username = $("#username").val();
                    let password = $("#password").val();
                    let repassword = $("#passwords").val();
                    if (password != repassword) {
                        alert("密码不同")
                        return;
                    } else if (password == "" || password == null) {
                        alert("密码不为空");
                        return;
                    }
                    $.post("../user", {
                            'username': username,
                            'password': password,
                            'passwords': repassword
                        }, function (data) {
                            if (data.massage == 1) {
                                let container = document.querySelector('.login-dialog');
                                let blogDiv = document.createElement('div');
                                blogDiv.className = 'row';
                                blogDiv.innerHTML = "注册成功,三秒自动跳转";
                                container.appendChild(blogDiv);
                                setTimeout(function () {
                                    window.location.href = "login.html";
                                }, 3000)
                            } else {
                                alert("用户名相同")
                            }
                        }
                    )
                })

        </script>
</body>
</html>